#include "speech_ser.hpp"
#include <gflags/gflags.h>

DEFINE_string(app_id,"","百度语音识别服务用户认证id");
DEFINE_string(api_key,"","百度语音识别服务用户认证密钥");
DEFINE_string(secret_key,"","百度语音识别服务用户密钥");
DEFINE_string(etcd_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(instance_name, "/speech/instance1", "当前实例名称");
DEFINE_string(base_service_dir, "/service", "服务监控根目录");
DEFINE_string(access_host, "127.0.0.1:10010", "当前实例的外部访问url");
DEFINE_int32(listen_host, 10010 , "rpc服务器的监听端口");
DEFINE_int32(timeout, -1 , "rpc调用超时时间");
DEFINE_int32(thread_cnt, 1 , "IO启动的线程数量,默认为1");
DEFINE_bool(mode,false,"发布/调试模式,设置为false表示调试模式,默认为这个值");
DEFINE_string(file,"./test.log","存放日志的文件名");
DEFINE_int32(level,0,"设置的日志等级,从低到高分为[0-6],默认为0");


int main(int argc,char*argv[])
{
    logging::LoggingSettings seeting;
    seeting.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(seeting);
    /*初始化gflags解析器*/
    google::ParseCommandLineFlags(&argc,&argv,true);
    //初始化日志器
    init(FLAGS_mode,FLAGS_file,FLAGS_level);
    //建造者模式构建语音识别服务器
    std::shared_ptr<SpeechServerBuilder> build = std::make_shared<SpeechServerBuilder>();
    build->MakeTransformerPtr(FLAGS_app_id,FLAGS_api_key,FLAGS_secret_key);
    build->MakeRegClientPtr(FLAGS_etcd_host,FLAGS_base_service_dir + FLAGS_instance_name,FLAGS_access_host);
    build->MakeBrpcServerPtr(FLAGS_listen_host,FLAGS_timeout,FLAGS_thread_cnt);
    auto server = build->Build();
    server->start();
    return 0;
}